package org.goj.practice.controller;

import cn.hutool.core.lang.Assert;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.goj.common.entity.practice.Duplicate;
import org.goj.common.model.Result;
import org.goj.practice.service.DuplicateService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 相似度检测表 前端控制器
 * </p>
 *
 * @author CK
 * @since 2021-05-12
 */
@RestController
@RequestMapping("/duplicate")
public class DuplicateController {

    @Resource
    private DuplicateService duplicateService;

    /**
     * 相似度检测
     *
     * @param solutionIds 评测ID集合
     * @param language    评测语言
     * @return Result<List < Duplicate>>
     * @author CK
     * @date 2021/5/12 15:38
     */
    @GetMapping("/detection")
    public Result<List<Duplicate>> detection(@RequestParam(value = "solutionIds") List<Integer> solutionIds,
                                             @RequestParam(value = "language") Integer language) {
        Assert.isTrue(solutionIds.size() > 0, "请选择需要检测的记录");
        List<Duplicate> list = duplicateService.detection(solutionIds, language);
        Assert.isTrue(list.size() > 0, "相似度检测失败");
        return Result.succeed("相似度检测成功", list);
    }

    @GetMapping("/listDuplicate")
    public Result<Page<Duplicate>> listDuplicate(
            @RequestParam(value = "current", required = false, defaultValue = "1") Integer current,
            @RequestParam(value = "size", required = false, defaultValue = "10") Integer size) {
        Page<Duplicate> page = new Page<>(current, size);
        Page<Duplicate> page1 = duplicateService.page(page);
        return Result.succeed("查询评测记录成功", page1);
    }

}

